﻿using Autodesk.AutoCAD.DatabaseServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CADTool.DotNetARX
{
    public static class TextTools
    {
        /// <summary>
        /// 多行文字堆叠方式
        /// </summary>
        public enum StackType
        {
            /// <summary>
            /// 水平分数(/)
            /// </summary>
            HorizontalFraction,
            /// <summary>
            /// 斜分数(#)
            /// </summary>
            ItalicFraction,
            /// <summary>
            /// 公差(^)
            /// </summary>
            Tolerance
        }
        /// <summary>
        /// 特殊字符
        /// </summary>
        public struct TextSpecialSymbol
        {
            #region 特殊字符
            /// <summary>
            /// 度符号(°)
            /// </summary>
            public static readonly string Degree = @"\U+00B0";
            /// <summary>
            /// 公差符号(±)
            /// </summary>
            public static readonly string Tolerance = @"\U+00B1";
            /// <summary>
            /// 直径符号(φ)
            /// </summary>
            public static readonly string Diameter = @"\U+2205";
            /// <summary>
            /// 几乎相等(≈)
            /// </summary>
            public static readonly string AlmostEqual = @"\U+2248";
            /// <summary>
            /// 角度(∠)
            /// </summary>
            public static readonly string Angle = @"\U+2220";
            /// <summary>
            /// 边界线
            /// </summary>
            public static readonly string LineBoundary = @"\U+E100";
            /// <summary>
            /// 中心线
            /// </summary>
            public static readonly string LineCenter = @"\U+2104";
            /// <summary>
            /// 增量(Δ)
            /// </summary>
            public static readonly string Delta = @"\U+0394";
            /// <summary>
            /// 电相位(φ)
            /// </summary>
            public static readonly string ElectricalPhase = @"\U+0278";
            /// <summary>
            /// 流线
            /// </summary>
            public static readonly string LineFlow = @"\U+E101";
            /// <summary>
            /// 标识
            /// </summary>
            public static readonly string Identity = @"\U+2261";
            /// <summary>
            /// 初始长度
            /// </summary>
            public static readonly string InitialLength = @"\U+E200";
            /// <summary>
            /// 界碑线
            /// </summary>
            public static readonly string LineMonument = @"\U+E102";
            /// <summary>
            /// 不相等(≠)
            /// </summary>
            public static readonly string Notequal = @"\U+2260";
            /// <summary>
            /// 欧姆
            /// </summary>
            public static readonly string Ohm = @"\U+2126";
            /// <summary>
            /// 欧米加(Ω)
            /// </summary>
            public static readonly string Omega = @"\U+03A9";
            /// <summary>
            /// 地界线
            /// </summary>
            public static readonly string LinePlate = @"\U+214A";
            /// <summary>
            /// 下标2
            /// </summary>
            public static readonly string Subscript2 = @"\U+2082";
            /// <summary>
            /// 平方
            /// </summary>
            public static readonly string Square = @"\U+00B2";
            /// <summary>
            /// 立方
            /// </summary>
            public static readonly string Cube = @"\U+00B3";
            #endregion
            #region 单行文字上下划线
            /// <summary>
            /// 单行文字上划线
            /// </summary>
            public static readonly string Overline = @"%%o";
            /// <summary>
            /// 单行文字下划线
            /// </summary>
            public static readonly string Underline = @"%%u";
            #endregion
            #region 希腊字母
            /// <summary>
            /// α
            /// </summary>
            public static readonly string Alpha = @"\U+03B1";
            /// <summary>
            /// β
            /// </summary>
            public static readonly string Belta = @"\U+03B2";
            /// <summary>
            /// γ 
            /// </summary>
            public static readonly string Gamma = @"\U+03B3";
            #endregion
            #region 钢筋符号
            /// <summary>
            /// 一级钢筋符号
            /// </summary>
            public static readonly string SteelBar1 = @"\U+0082";
            /// <summary>
            /// 二级钢筋符号
            /// </summary>
            public static readonly string SteelBar2 = @"\U+0083";
            /// <summary>
            /// 三级钢筋符号
            /// </summary>
            public static readonly string SteelBar3 = @"\U+0084";
            /// <summary>
            /// 四级钢筋符号
            /// </summary>
            public static readonly string SteelBar4 = @"\U+0085";
            #endregion
        }
        public static void SetFromTextStyle(this DBText txt)
        {
            //打开文字样式表记录
            TextStyleTableRecord tstr = (TextStyleTableRecord)txt.TextStyleId.GetObject(OpenMode.ForRead);
            if (!txt.IsWriteEnabled) txt.UpgradeOpen(); //必须保证文字为写的状态
            txt.Oblique = tstr.ObliquingAngle; //设置倾斜角度（弧度）
            txt.Annotative = tstr.Annotative; //设置文字的注释性
            //文字的方向与布局是否相匹配
            txt.SetPaperOrientation(Convert.ToBoolean(tstr.PaperOrientation));
            txt.WidthFactor = tstr.XScale;  //设置文字的宽度比例
            txt.Height = tstr.TextSize; //设置文字的高度
            if (tstr.FlagBits==2)  //颠倒
            {
                txt.IsMirroredInX = true;
            }
            else if(tstr.FlagBits==4)  //反向
            {
                txt.IsMirroredInY = true;
            }
            else if(tstr.FlagBits==6) //颠倒并反向
            {
                txt.IsMirroredInX=txt.IsMirroredInY = true;
            }
            txt.DowngradeOpen();
        }
    }
}
